const Api = {
    // 用户注册
    register(user) {
        return {
            method: 'post',
            url: '/api/user',
            data: user
        }
    },
    //用户登录
    login({username: username, password: password}) {
        return {
            url: '/api/user/session',
            params: {
                username: username,
                password: password
            }
        }
    },
    //获取用户信息
    getUserInfo() {
        return {
            url: '/api/user/info'
        }
    },
    //修改用户信息
    modifyUserInfo(user){
        return {
            method: 'put',
            url: '/api/user',
            data: user
        }
    },
    //用户登出
    logout() {
        return {
            method: 'delete',
            url: '/api/user/session'
        }
    },
    //获取文章集合
    getArticleList(aid = null, page = 1, size = 10) {
        let params = {
            page: page,
            size: size
        }
        if (aid) {
            params.aid = aid
        }
        return {
            url: '/api/article',
            params: params
        }
    },
    //根据关键字获取文章集合
    getArticleListByKeyWord(aid = null, keyWord = null, page = 1, size = 10) {
        let params = {
            keyWord: keyWord,
            page: page,
            size: size
        }
        if (aid) {
            params.aid = aid
        }
        return {
            url: '/api/article/filter',
            params: params
        }
    },
    //添加文章
    addArticle(article) {
        return {
            method: 'post',
            url: '/api/article',
            data: article
        }
    },
    //根据文章id获取文章
    getArticleContent(id) {
        return {
            url: `/api/article/${id}`
        }
    },
    //更新文章
    updateArticle(article) {
        return {
            method: 'put',
            url: '/api/article',
            data: article
        }
    },
    //删除文章
    deleteArticle(article) {
        return {
            method: 'delete',
            url: `/api/article`,
            data: article
        }
    }

}